package org.itboys.core.service.mysql.front;

import org.itboys.core.dto.tray.SundayTrayModelDto;
import org.itboys.core.entity.mysql.tray.SundayTrayModel;
import org.itboys.framework.resource.ResourceHolder;
import org.itboys.mysql.service.BaseMySqlService;
import org.itboys.param.ParamUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 作者：zzq
 * 时间：2018/12/5
 * 描述：托盘模板
 */
@Service
public class SundayFrontTrayModelService extends BaseMySqlService<SundayTrayModel> {
    @Autowired
    private ResourceHolder resourceHolder;

    /**
     * @param request
     * @return
     */
    public List<SundayTrayModelDto> select(HttpServletRequest request) {
        Map<String, Object> param = ParamUtil.packageMysqlPageParam(request, "");
        return packageMultiDto(super.select(param));
    }

    /**
     * 组装多个
     *
     * @param models
     * @return
     */
    public List<SundayTrayModelDto> packageMultiDto(List<SundayTrayModel> models) {
        List<SundayTrayModelDto> dtos = new ArrayList<>();
        for (SundayTrayModel model : models) {
            SundayTrayModelDto dto = new SundayTrayModelDto();
            BeanUtils.copyProperties(model, dto);
            dto.setImage(resourceHolder.getStringValue("imgRoot")+model.getImage());
            dtos.add(dto);
        }
        return dtos;
    }

}
